package ACWing.DataStructure.栈;
//

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/27 21:35
 */
public class DoubleLinkedList {
    static int[]e=new int[100010];
    static int[]r=new int[100010];
    static int[]l=new int[100010];
    static int idx=0;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m=sc.nextInt();
        sc.nextLine();
        r[0] = 1;l[1] = 0;
        idx = 2;
        while (m-->0){
            String s=sc.next();
            if("L".equals(s)){
                int x=sc.nextInt();
                add(0,x);
            }
            if("R".equals(s)){
                int x=sc.nextInt();
                add(l[1],x);
            }
            if("D".equals(s)){
                int x=sc.nextInt();
                remove(x+1);
            }
            if("IL".equals(s)){
                int k=sc.nextInt();
                int x=sc.nextInt();
                add(l[k+1],x);
            }
            if("IR".equals(s)){
                int k=sc.nextInt();
                int x=sc.nextInt();
                add(k+1,x);
            }
        }
        for (int i = r[0]; i != 1; i=r[i]) {
            System.out.print(e[i]+" ");
        }
    }
    public static void add(int k,int x){
        e[idx]=x;
        r[idx]=r[k];
        l[idx]=k;
        l[r[k]]=idx;
        r[k]=idx++;

    }
    public static void remove(int k){
        l[r[k]]=l[k];
        r[l[k]]=r[k];
    }
}

